package com.jjpro.handle;


import com.jjpro.exception.SiteException;
import com.jjpro.utils.AppletResult;
import com.jjpro.utils.ResultUtil;
import com.jjpro.utils.common.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionHandle {
    private Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public AppletResult handle(Exception e) {
        if (e instanceof SiteException) {
            SiteException siteException = (SiteException) e;
            return ResultUtil.errorH5(siteException.getCode(), siteException.getMessage());
        } else {
            logger.error("[系统异常] {}", e);
            return ResultUtil.errorH5(-1, "系统内部错误");
        }
    }
}
